Usage example
var p1 = L.point(10, 10),
p2 = L.point(40, 60),
bounds = L.bounds(p1, p2);
All Leaflet methods that accept Bounds
objects also accept them in a simple Array form (unless noted otherwise), so the bounds example above can be passed like this:
所有接受Bounds对象的Leaflet方法也以简单的Array形式接受它们(除非另有说明),因此上面的边界示例可以这样传递:
otherBounds.intersects([[10, 10], [40, 60]]);
Note that Bounds
does not inherit from Leaflet’s Class
object, which means new classes can’t inherit from it, and new methods can’t be added to it with the include
function.
注意,Bounds不会从Leaflet的Class对象继承,这意味着新的类不能从它继承,并且不能使用include函数向它添加新的方法。
Creation
Factory | Description |
---|---|
L.bounds(<Point> corner1, <Point> corner2) | Creates a Bounds object from two corners coordinate pairs. 从两个角坐标对创建边界对象。 |
L.bounds(<Point[]> points) | Creates a Bounds object from the given array of points. 从给定的点阵列创建边界对象。 |
Methods
Method | Returns | Description |
---|---|---|
extend(<Point> point) | this | Extends the bounds to contain the given point. 扩展边界以包含给定点。 |
extend(<Bounds> otherBounds) | this | Extend the bounds to contain the given bounds 扩展边界以包含给定的边界 |
getCenter(<Boolean> round?) | Point | Returns the center point of the bounds. 返回边界的中心点。 |
getBottomLeft() | Point | Returns the bottom-left point of the bounds. 返回边界的左下角点。 |
getTopRight() | Point | Returns the top-right point of the bounds. 返回边界的右上角。 |
getTopLeft() | Point | Returns the top-left point of the bounds (i.e. this.min ).返回边界的左上点(即this.min)。 |
getBottomRight() | Point | Returns the bottom-right point of the bounds (i.e. this.max ).返回边界的右下点(即this.max)。 |
getSize() | Point | Returns the size of the given bounds 返回给定边界的大小 |
contains(<Bounds> otherBounds) | Boolean | Returns true if the rectangle contains the given one.如果矩形包含给定的矩形,则返回true。 |
contains(<Point> point) | Boolean | Returns true if the rectangle contains the given point.如果矩形包含给定点,则返回true。 |
intersects(<Bounds> otherBounds) | Boolean | Returns true if the rectangle intersects the given bounds. Two bounds intersect if they have at least one point in common.如果矩形与给定边界相交,则返回true。如果两个边界至少有一个公共点,则它们相交。 |
overlaps(<Bounds> otherBounds) | Boolean | Returns true if the rectangle overlaps the given bounds. Two bounds overlap if their intersection is an area.如果矩形与给定边界重叠,则返回true。如果两个边界的交点是一个区域,则两个边界重叠。 |
isValid() | Boolean | Returns true if the bounds are properly initialized.如果边界正确初始化,则返回true。 |
pad(<Number> bufferRatio) | Bounds | Returns bounds created by extending or retracting the current bounds by a given ratio in each direction. For example, a ratio of 0.5 extends the bounds by 50% in each direction. Negative values will retract the bounds. 返回通过在每个方向上按给定比率扩展或收缩当前边界而创建的边界。例如,0.5的比率将边界在每个方向上扩展50%。负值将收回边界。 |
equals(<Bounds> otherBounds) | Boolean | Returns true if the rectangle is equivalent to the given bounds.如果矩形等于给定边界,则返回true。 |
Properties
Property | Type | Description |
---|---|---|
min | Point | The top left corner of the rectangle. 矩形的左上角。 |
max | Point | The bottom right corner of the rectangle. 矩形的右下角。 |